package br.org.senai.controller;

import br.org.senai.model.Ferramenta;
import br.org.senai.model.Locacao;
import br.org.senai.model.Pessoa;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * <property name="javax.persistence.sql-load-script-source" value="META-INF/dumpEstudoJPA.sql"/>
 * 
 * @author william
 */

public class GeraBanco {
    public static void main(String[] args) {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("EstudoMapeamentoPU");
        EntityManager em = factory.createEntityManager();
        
        List<Ferramenta> ferramentas = new ArrayList<>();
        ferramentas.add(em.find(Ferramenta.class, 1));
        ferramentas.add(em.find(Ferramenta.class, 2));
        
        Locacao loc = new Locacao();
        loc.setDatLocacao(new Date());
        loc.setEntregue("N");
        loc.setFerramentas(ferramentas);
        loc.setPessoa(em.find(Pessoa.class, 1L));
        
        em.getTransaction().begin();
        em.persist(loc);
        em.getTransaction().commit();
        
        em.close();
        factory.close();        
    }
}
